package SecureChat;



public class Convert {
 
        public static String toHex (byte buf[]) {
            StringBuffer strbuf = new StringBuffer(buf.length * 2);
            int i;
            for (i = 0; i < buf.length; i++) {
                if (((int) buf[i] & 0xff) < 0x10)
                    strbuf.append("0");
                strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
            }
        return strbuf.toString();
        }
        
        
        public static byte[] toByte (String s) {
            String s2;
            byte[] b = new byte[s.length() / 2];
            int i;
            for (i = 0; i < s.length() / 2; i++) {
                s2 = s.substring(i * 2, i * 2 + 2);
                b[i] = (byte)(Integer.parseInt(s2, 16) & 0xff);
            }
            return b;
        }    
        
    
        public static void Hexprint(byte[] hash)
        {
            //Test Print function for Hash HEX value

            //Cenvert Byte[] to HEX format
            for(int i=0 ; i < hash.length ; i++){
                System.out.print(String.format("0x%02X ", hash[i]));
                    if(0 == (i+1)%4){  
                        System.out.println();
                    }
            }

            System.out.print("Byte length is : ");
            System.out.println(hash.length);
        }   
}
